<?php
/**
 * communit.as
 * @copyright (C)2008 Jaybill McCarthy, All Rights Reserved.
 * @category communitas
 * @package communitas
 * @author Jaybill McCarthy
 * @link http://communit.as communit.as
 * @license http://communit.as/docs/license License
 */

/**
 *
 * @package communitas
 * @subpackage forum_lib
 * @license http://communit.as/docs/license License 
 */
 
abstract class Forum_Controller_Action_Abstract extends Cts_Controller_Action_Abstract{

    function init() {
    	
    	    
		parent::init();
		$this->view->pagetitle = "Forum";
		
		$this->_filter = @new FilterBBCode();
		
		$this->view->body_class = "forum";
		$this->view->scripts = array('forums.js');	
		
		$users_table = new Users();
		$activity_timeout = Cts_Registry::get('forum_activity_timeout_seconds','forum');
		$user_limit = Cts_Registry::get('forum_max_users_shown','forum');
		
		if($user_limit == 0){
			$user_limit = null;
		}
		$users = $users_table->fetchAll('last_activity_on > (select now() - interval '.$activity_timeout.' second)','last_activity_on desc',$user_limit);
	    $tmp_users = array();
	    if(count($users) > 0){
	    	
	    	foreach($users as $user){
	    		$user = $user->toArray();	    		
	    		$user['sign'] = Cts_Common::calculateAstroSign(strtotime($user['birthday']));
	    		$user['age'] = Cts_Common::calculateYearsOld(strtotime($user['birthday']));
	    		$countries_table = new Countries();
	    		$where = $countries_table->getAdapter()->quoteInto('country_code = ?',$user['country_code']);
	    		$country = $countries_table->fetchRow($where);
	    		if(!is_null($country)){
	    			$user['location'] = $country->country; 
	    		}
	    		$media = $users_table->getProfileMedia($user['username']);
	    		if(!is_null($media)){
	    			$user['media'] = $media->toArray();
	    		}
	    		$tmp_users[] = $user;
	    	}
	    	$this->view->users = $tmp_users;	
	    }
						
	  }
}
